package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.object.pojo.dto.*;
import com.tbit.uqbike.object.pojo.vo.DepositDetailVO;
import com.tbit.uqbike.object.pojo.vo.DepositIncomeVO;
import com.tbit.uqbike.object.pojo.vo.DepositTotalDetailVO;
import com.tbit.uqbike.object.pojo.vo.DepositTotalIncomeVO;
import com.tbit.common.entity.view.PageResult;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.AdvanceDepositStatService;
import com.tbit.uqbike.service.business.DepositStatService;
import com.tbit.uqbike.webmanager.util.StringUtil;
import com.tbit.uqbike.webmanager.util.csv.annotations.AsyncDownload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 财务统计-押金统计
 *
 * @AUTHOR: wei.xing
 * @DATE: 2022-11-11 14:16
 **/
@RestController
@RequestMapping("/depositStat")
public class DepositStatController {

    @Autowired
    private DepositStatService service;
    @Resource
    private AdvanceDepositStatService depositStatService;


    /**
     * 获取押金详情的数据截止时间
     *
     * @param accountIds 区域id 多个用,隔开
     * @return
     */
    @GetMapping("/getDetailLastTime")
    public Result<Long> getDetailLastTime(String accountIds) {
        List<Integer> idList = StringUtil.getIntegerList(accountIds);
        Long updateTime = service.getLastTime(idList);
        return Result.success(updateTime);
    }


    /**
     * 获取押金详情的汇总
     *
     * @param dto
     * @return
     */
    @GetMapping("/getTotalDetail")
    public Result<DepositTotalDetailVO> getTotalDetail(StatDetailDTO dto) {
        DepositTotalDetailVO detailVO = service.getTotalDetail(dto);
        return Result.success(detailVO);
    }

    /**
     * 获取押金详情的分页
     *
     * @param dto
     * @return
     */
    @GetMapping("/getDetailPage")
    public Result<PageResult<DepositDetailVO>> getDetailPage(StatDetailPageDTO dto) {
        PageResult<DepositDetailVO> page = service.getDetailPage(dto);
        return Result.success(page);
    }


    /**
     * 押金详情的账单下载
     *
     * @param dto
     * @return
     */
    @AsyncDownload(defaultFileName = "押金详情")
    @PostMapping("/exportDetail")
    public Result exportDetail(@RequestBody StatDetailDownloadDTO dto) {
        String url = service.exportDetail(dto);
        return Result.success(url);
    }


    /**
     * 获取押金收支的汇总
     *
     * @param dto
     * @return
     */
    @GetMapping("/getIncomeTotalDetail")
    public Result<DepositTotalIncomeVO> getTotalIncome(DepositIncomeDTO dto) {
        DepositTotalIncomeVO detailVO = service.getTotalIncome(dto);
        return Result.success(detailVO);
    }

    /**
     * 获取押金收支明细的分页
     *
     * @param pageDTO
     * @return
     */
    @GetMapping("/getIncomeDetailPage")
    public Result<PageResult<DepositIncomeVO>> getIncomeDetailPage(DepositIncomePageDTO pageDTO) {
        PageResult<DepositIncomeVO> pageResult = service.getIncomeDetailPage(pageDTO);
        return Result.success(pageResult);
    }


    /**
     * 押金收支明细的账单下载
     *
     * @param dto
     * @return
     */
    @AsyncDownload(defaultFileName = "押金收支明细")
    @PostMapping("/exportIncomeDetail")
    public Result exportIncome(@RequestBody AdvanceDepositIncomeDownloadDTO dto) {
        String url = depositStatService.exportIncome(dto);
        return Result.success(url);
    }

}
